package top.lingkang.fas.admin.mapper;

import com.mybatisflex.core.BaseMapper;
import eu.bitwalker.useragentutils.UserAgent;
import org.noear.solon.core.handle.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.lingkang.fas.admin.entity.SysLogininforEntity;

/**
 * 系统访问记录 映射层。
 *
 * @author Administrator
 * @since 2025-07-20
 */
public interface SysLogininforMapper extends BaseMapper<SysLogininforEntity> {

    default void add(String username,String status, String msg) {
        SysLogininforEntity entity = new SysLogininforEntity();
        entity.setUserName(username);
        entity.setMsg(msg);
        entity.setStatus(status);
        Context context= Context.current();
        UserAgent userAgent = UserAgent.parseUserAgentString(context.header("User-Agent"));
        entity.setIpaddr(context.realIp());
        entity.setBrowser(userAgent.getBrowser().getName());
        entity.setOs(userAgent.getOperatingSystem().getName());
        this.insert(entity);
    }
}
